﻿using System;
using System.Collections.Generic;
using System.Web;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using SubjectWorkShop.Core;

namespace SubjectWorkShop.Web.App_Code.HttpHandlers
{
    public class LayerBlocks : IHttpHandler
    {
        #region IHttpHandler 成员

        public bool IsReusable
        {
            get
            {
                return true;
            }
        }

        public void ProcessRequest(HttpContext context)
        {
            string xmlpath = System.Web.Hosting.HostingEnvironment.MapPath(SubjectSettings.Instance.StorageLocation + @"LayerBlocks.xml");
            string xsltpath = System.Web.Hosting.HostingEnvironment.MapPath(SubjectSettings.Instance.Transformlocation + @"LayerBlocks.xslt");
            XmlDocument doc = new XmlDocument();

            context.Response.Clear();
            context.Response.ContentType = "text/xml";

            //XSL处理文档
            XslCompiledTransform trans = new XslCompiledTransform();
            try
            {
                trans.Load(xsltpath);
                doc.Load(xmlpath);
                trans.Transform(doc, null, context.Response.OutputStream);
            }
            catch (XmlException ex)
            {
                throw new Exception("内容不符合标准", ex);
            }
            context.Response.End();

            
            
            
        }

        #endregion
    }
}
